package org.xenon.vote.model.pojo.po;

import javax.validation.constraints.Email;
import javax.validation.constraints.Max;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Objects;

/**
 * 裁判对象
 */
public class Judge {

    /**
     * 裁判密码
     */
    @NotBlank(message = "password.blank")
    @NotNull(message = "password.null")
    private String password;

    /**
     * 裁判名字
     * 登录名
     */
    @NotNull(message = "name.null")
    @NotBlank(message = "name.blank")
    private String name;

    /**
     * 裁判所属的投票号
     */
    @NotNull(message = "countId.null")
    private int turn;

    /**
     * 所有者邮箱
     */
    @NotNull(message = "mail.null")
    @NotBlank(message = "mail.blank")
    @Email(message = "mail.format")
    @Max(value = 128)
    private String owner;

    public Judge(@NotNull(message = "name.null")
                 @NotBlank(message = "name.blank") String name,
                 @NotBlank(message = "password.blank")
                 @NotNull(message = "password.null") String password,
                 @NotNull(message = "countId.null") int turn,
                 @NotNull(message = "mail.null")
                 @NotBlank(message = "mail.blank")
                 @Email(message = "mail.format")
    @Max(value = 128) String owner) {
        this.password = password;
        this.name = name;
        this.turn = turn;
        this.owner = owner;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getTurn() {
        return turn;
    }

    public void setTurn(int turn) {
        this.turn = turn;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Judge judge = (Judge) o;
        return turn == judge.turn &&
                name.equals(judge.name) &&
                owner.equals(judge.owner);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, turn, owner);
    }
}
